package com.woniu.sharepark.platformsystem.service.impl;

import com.woniu.sharepark.platformsystem.dao.ScaleDAO;
import com.woniu.sharepark.platformsystem.pojo.Scale;
import com.woniu.sharepark.platformsystem.service.ScaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zy
 * @date 2019/6/5 19:32
 */
@Service
public class ScaleServiceImpl implements ScaleService {

    @Resource
    private ScaleDAO scaleDAO;


    /**
     * 修改数据库里的比例表，同时更新redis中的缓存的数据
     * @param scale
     * @return
     */
    @Override
    @CachePut(value = "scale",key = "#scale.sId")
    public Scale updateScale(Scale scale) {

        try {
            int result = scaleDAO.updateScale(scale);
            return scaleDAO.findScale();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 查询数据库里的比例表，并缓存到redis中，下次再查就可以直接查缓存里的了
     * @return
     */
    @Override
    @Cacheable(value = "scale",key = "1")
    public Scale findScale() {
        return scaleDAO.findScale();
    }
}
